using System;

namespace PoshRabbit
{
    public abstract class SharedConnectionRabbitCmdletBase : RabbitCmdletBase
    {
        protected bool CanShareConnection
        {
            get
            {
                return !(String.IsNullOrEmpty(HostName) ||
                         String.IsNullOrEmpty(RoutingKey) ||
                         String.IsNullOrEmpty(Exchange));
            }
        }

        protected override void BeginProcessing()
        {
            if (! CanShareConnection)
            {
                return;
            }
            CreateModel();           
        }

        protected override void ProcessRecord()
        {
            if (! CanShareConnection)
            {
                CreateModel();
            }
 
            base.ProcessRecord();
        }
        protected override void EndProcessing()
        {
            DestroyModel();
        }

        protected override void StopProcessing()
        {
            DestroyModel();
        }
    }
}